import { boot } from 'quasar/wrappers'

// "async" is optional;
// more info on params: https://v2.quasar.dev/quasar-cli/boot-files
export default boot(async ({ router, store }) => {
  // 如果没有登陆，则跳到主页去 但是看起来这玩意像是一次性的
  router.beforeEach((to, from, next) => {
    if (store.getters['session/isLogined']) {
      store.dispatch('session/validate')
    }
    // 现在我们要检查其是否满足需要
    const protectedRoute = to.matched.some(route => route.meta.auth)
    if (!protectedRoute) next()
    else if (store.getters['session/isLogined']) {
      store.dispatch('session/validate')
      console.log('?', store.getters['session/getUser'])
      next()
    } else {
      next('login')
    }
  })
})
